<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/WEB-INF/jsp/common/tags.jsp"%>

<aos:html title="产品管理" base="http" lib="ext">
<aos:body>
</aos:body>
</aos:html>


<aos:onready>
	<aos:viewport layout="border">
		<aos:formpanel id="_f_query" layout="column" labelWidth="70"
			header="false" region="north" border="false">
			<aos:docked forceBoder="0 0 1 0">
				<aos:dockeditem xtype="tbtext" text="查询条件" />
			</aos:docked>
			<aos:textfield name="product_name" fieldLabel="产品名称"   columnWidth="0.15" />
			<aos:textfield name="product_type" fieldLabel="产品类型"   columnWidth="0.15" />
			<aos:combobox name="catalogy_id" fieldLabel="产品大类"  dicField="catalogy_type_"  columnWidth="0.18"/>
			<aos:combobox name="type_id" fieldLabel="产品小类"  dicField="product_type_" columnWidth="0.25" />
			<aos:combobox name="is_spe" fieldLabel="是否特价"  dicField="is_" columnWidth="0.1"/>
			<aos:combobox name="is_rec" fieldLabel="是否推荐"  dicField="is_" columnWidth="0.1"/>
			<aos:combobox name="is_valid" fieldLabel="是否有效"  dicField="is_" columnWidth="0.1"/>
			<aos:combobox name="is_parent" fieldLabel="是否父产品"  dicField="is_" columnWidth="0.1"/>
			<aos:docked dock="bottom" ui="footer" margin="0 0 8 0">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem xtype="button" text="查询" onclick="_g_product_query" icon="query.png" />
				<aos:dockeditem xtype="button" text="重置" onclick="AOS.reset(_f_query);" icon="refresh.png" />
				<aos:dockeditem xtype="button" text="添加新产品" onclick="_w_product_add_show()" icon="add.png" />
				<aos:dockeditem xtype="tbfill" />
			</aos:docked>
		</aos:formpanel>

		<aos:gridpanel id="_g_product" url="productService.list"
			onrender="_g_product_query" region="center">
			<aos:docked forceBoder="1 0 1 0">
				<aos:dockeditem xtype="tbtext" text="产品信息" />
			</aos:docked>
			<aos:column type="rowno" />
			<aos:column header="流水号id" dataIndex="id" hidden="true" />
			<aos:column header="父产品id" dataIndex="parent_id" hidden="true"/>
			<aos:column header="产品名称" dataIndex="product_name"/>
			<aos:column header="产品类型" dataIndex="product_type" hidden="true"/>
			<aos:column header="产品主图" dataIndex="main_url" hidden="true"/>
			<aos:column header="折后价" dataIndex="discount_price" type="number" />
			<aos:column header="原价" dataIndex="full_price" type="number" hidden="true"/>
			<aos:column header="排序" dataIndex="sort"/>
			<aos:column header="产品描述" dataIndex="discription" hidden="true"/>
			<aos:column header="产品大类" dataIndex="catalogy_id" rendererField="catalogy_type_"/>
			<aos:column header="产品小类" dataIndex="type_id" rendererField="product_type_"/>
			<aos:column header="是否特殊" dataIndex="is_spe" rendererField="is_"/>
			<aos:column header="是否推荐" dataIndex="is_rec" rendererField="is_"/>
			<aos:column header="是否有效" dataIndex="is_valid" rendererField="is_"/>
			<aos:column header="创建时间" dataIndex="create_date" type="date"	format="Y-m-d H:i:s"/>
			<aos:column header="修改时间" dataIndex="modify_date" type="date"	format="Y-m-d H:i:s"/>
			<aos:column header="添加子产品" rendererFn="fn_button_render2" align="center"/>
			<aos:column header="编辑" rendererFn="fn_button_render" align="center" />
			
		</aos:gridpanel>
       



		
		<aos:window id="_w_product" title="产品编辑"	onshow="_w_product_onshow">
			<aos:formpanel id="_f_product" width="400" layout="anchor"	labelWidth="70">
				<aos:textfield name="id" fieldLabel="流水号id"  readOnly="true" />
				<aos:textfield name="parent_id" fieldLabel="父产品id"  />
				<aos:textfield name="product_name" fieldLabel="产品名称"  />
				<aos:textfield name="product_type" fieldLabel="产品类型"  />
				<aos:textfield name="main_url" fieldLabel="产品主图"  />
				<aos:textfield name="discount_price" fieldLabel="折扣价"  />
				<aos:textfield name="full_price"     fieldLabel="原价"  />
				<aos:textfield name="sort" fieldLabel="排序"	 />
				<aos:htmleditor name="discription" fieldLabel="产品描述"  />
				<aos:combobox name="catalogy_id" fieldLabel="大类id"  dicField="catalogy_type_"/>
				<aos:combobox name="type_id" fieldLabel="小类id"  dicField="product_type_"/>
				<aos:combobox name="is_spe" fieldLabel="是否特殊"  dicField="is_"/>
				<aos:combobox name="is_rec" fieldLabel="是否推荐"  dicField="is_"/>
				<aos:combobox name="is_valid" fieldLabel="是否有效" dicField="is_"/>
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="updateProduct()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_product.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>
       
       
       <aos:window id="_w_product_add" title="产品添加"	onshow="_w_product_add_onshow">
			<aos:formpanel id="_f_product_add" width="400" layout="anchor"	labelWidth="70">
				<aos:textfield name="parent_id" fieldLabel="父产品id" />
				<aos:textfield name="product_name" fieldLabel="产品名称"  />
				<aos:textfield name="product_type" fieldLabel="产品类型"  />
				<aos:formpanel id="pic_add_">
						<aos:filefield name="uploadPic" id="uploadPic" star="true"	emptyText="请上传图片..." />
						<aos:dockeditem text="上传图片" icon="add2.png" onclick="add_upload('_f_product_add.main_url')" />
			    </aos:formpanel>
				<aos:textfield name="main_url" fieldLabel="产品主图"  allowBlank="false"/>
				<aos:textfield name="discount_price" fieldLabel="折扣价"  allowBlank="false"/>
				<aos:textfield name="full_price"     fieldLabel="原价"  allowBlank="false"/>
				<aos:textfield name="sort" fieldLabel="排序"	 allowBlank="false"/>
				<aos:htmleditor name="discription" fieldLabel="产品描述"  />
				<aos:combobox name="catalogy_id" fieldLabel="大类id"  dicField="catalogy_type_"/>
				<aos:combobox name="type_id" fieldLabel="小类id"  dicField="product_type_"/>
				<aos:combobox name="is_spe" fieldLabel="是否特殊"  dicField="is_"/>
				<aos:combobox name="is_rec" fieldLabel="是否推荐"  dicField="is_"/>
				<aos:combobox name="is_valid" fieldLabel="是否有效" dicField="is_"/>
			</aos:formpanel>
			<aos:docked dock="bottom" ui="footer">
				<aos:dockeditem xtype="tbfill" />
				<aos:dockeditem onclick="addProduct()" text="提交" icon="ok.png" />
				<aos:dockeditem onclick="#_w_product_add.hide();" text="关闭" icon="close.png" />
			</aos:docked>
		</aos:window>

		

	</aos:viewport>

	<script type="text/javascript">
		//加载表格数据
		function _g_product_query() {
			var params = AOS.getValue('_f_query');
			_g_product_store.getProxy().extraParams = params;
			_g_product_store.loadPage(1);
		}
		
		//窗口弹出事件监听
		function _w_product_onshow() {
			var record = AOS.selectone(_g_product);
            AOS.ajax({
            	params : {
            		id: record.data.id
            	},
                url: 'productService.getProductInfo',
                ok: function (data) {
                	_f_product.form.setValues(data);
                }
            });
		}
		
		//更新产品
		function updateProduct() {
			AOS.ajax({
				forms : _f_product,
                url: 'productService.updateProductInfo',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_product_store.reload();
					_w_product.hide();
                }
            });
		}
		
		//添加产品
		function addProduct() {
			AOS.ajax({
				forms : _f_product_add,
                url: 'productService.addProductInfo',
                ok: function (data) {
                	AOS.tip(data.appmsg);
					_g_product_store.reload();
					_w_product.hide();
                }
            });
		}
		
		
		//按钮列转换
		function fn_button_render(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="编辑" class="cbtn" onclick="_w_product_show();" />';
		}
		
		function fn_button_render2(value, metaData, record, rowIndex, colIndex,
				store) {
			return '<input type="button" value="添加子产品" class="cbtn"  onclick="_w_product_add_show(\''+record.data.id+'\')" />';
		}
		
		//上传图片
		function add_upload(setValueId){
			var form = pic_add_.getForm();
		    form.submit({
		       url: '/orisper/api/common/uploadPic.jhtml',
		       success: function(form, action) {
		    	   if(action.result.appcode == '-1'){
		        		AOS.tip(action.result.appmsg);
		        	}else{
		        		AOS.tip(action.result.appmsg); 
		        		AOS.setValue(setValueId, action.result.url);
		        	}
		       },
		       failure: function(form, action) {
		    	   AOS.tip("上传失败！");
		       }
		       
			}); 
		}
		
		
		
		
		
	</script>
</aos:onready>

<script type="text/javascript">

//显示预览1窗口
function _w_product_show(){
	Ext.getCmp('_w_product').show();
}

function _w_product_add_show(parentId){
	if(typeof(parentId)!="undefined"){
		AOS.setValue('_f_product_add.parent_id', parentId);
	}else{
		AOS.setValue('_f_product_add.parent_id', null);
	}
	Ext.getCmp('_w_product_add').show();
}
	
	
</script>